from abc import ABC, abstractmethod
import matplotlib.pyplot as plt

class Plotter(ABC):
    @abstractmethod
    def plot(self, data, *args, **kwargs):
        pass

class PointPlotter(Plotter):
    def plot(self, data, *args, **kwargs):
        x = [p[0] for p in data]
        y = [p[1] for p in data]
        plt.plot(x, y, *args, **kwargs)
        plt.show()

class ArrayPlotter(Plotter):
    def plot(self, data, *args, **kwargs):
        num_dims = len(data)
        if num_dims < 2 or num_dims > 3:
            raise ValueError("Input data should have 2 or 3 dimensions.")
        if len(data[0]) != len(data[1]):
            raise ValueError("Arrays for x and y should have the same length.")
        if num_dims == 3 and len(data[0]) != len(data[2]):
            raise ValueError("Arrays for x and z should have the same length.")
        
        if num_dims == 2:
            x = data[0]
            y = data[1]
            plt.plot(x, y, *args, **kwargs)
            plt.show()
        elif num_dims == 3:
            x = data[0]
            y = data[1]
            z = data[2]
            fig = plt.figure()
            ax = fig.add_subplot(111, projection='3d')
            ax.plot(x, y, z, *args, **kwargs)
            plt.show()

# 测试 PointPlotter
data = [[1, 2], [3, 4], [5, 6]]
plotter = PointPlotter()
plotter.plot(data)

# 测试 ArrayPlotter
data_2d = [[1, 2, 3], [4, 5, 6]]
data_3d = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
plotter_2d = ArrayPlotter()
plotter_3d = ArrayPlotter()
plotter_2d.plot(data_2d)
plotter_3d.plot(data_3d)
